import { parseTimeDot } from "@/utils/utils.js";
import { getLike } from "@/static/js/message.js";
import { checkQuiz } from "@/static/js/my.js";
export default {
  data() {
    return {
      parseTimeDot,
      likeList: [],
      page: 1,
      noMore: "noMore",
      isLoading: false,
    };
  },
  methods: {
    async getLikeList() {
      this.isLoading = true;
      this.noMore = "loading";
      const currentDate = new Date();
      const currentYear = currentDate.getFullYear();
      const res = await getLike({
        page: this.page,
        pageSize: 10,
        type: 2,
      });
      if (res.code == 1) {
        if (res.data.length == 0 || res.data.length < 10) {
          this.noMore = "noMore";
        } else {
          this.noMore = "loadmore";
        }
        let list = res.data;
        list.forEach((e) => {
          const updateTime = new Date(e.updatetime * 1000);
          const updateYear = updateTime.getFullYear();
          if (currentYear === updateYear) {
            e.updatetime = parseTimeDot(e.updatetime, "{m}-{d} {h}:{i}");
          } else {
            e.updatetime = parseTimeDot(e.updatetime, "{y}-{m}-{d} {h}:{i}");
          }
        });
        this.likeList.push(...res.data);
        uni.stopPullDownRefresh();
      }
      this.isLoading = false;
    },

    go(url) {
      uni.navigateTo({
        url: url,
      });
    },

    async goCheck(item) {
      const res = await checkQuiz({
        quiz_id: item.quiz_id,
      });
      if (res.code == 1) {
        uni.navigateTo({
          url: "/quiz/askInfo/index?id=" + item.quiz_id,
        });
      } else if (res.code == 3) {
        uni.showToast({
          title: res.msg,
          icon: "none",
        });
      }
    },
  },

  onPullDownRefresh() {
    this.isLoading = true;
    this.likeList = [];
    this.page = 1;
    this.noMore = "loadmore";
    this.getLikeList();
  },
  onReachBottom() {
    if (this.noMore == "noMore") return;
    this.page++;
    this.getLikeList();
  },
  onLoad(e) {
    this.isLoading = true;
    this.getLikeList();
  },
};